package com.itheima.threadDemo.Demo9;

public class cooker extends Thread {
    @Override
    public void run() {
        //while循环
        while (true) {
            //锁
            synchronized (Desk.lock) {
                //判断是否有汉堡
                if (Desk.count == 0) {
                    break;
                } else {
                    //一开始定义为false
                    if (!Desk.flag) {
                        System.out.println("做汉堡");
                        //修改标记
                        Desk.flag = true;
                        //唤醒锁下正在睡眠的线程
                        Desk.lock.notifyAll();
                    }else{
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
